package network;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;

public class UdpDictServer extends UdpEchoServer {
    //用哈希表，充当词典
    HashMap<String,String> dict = null;
    //需要手动调用一下构造方法，否则可能出错
    public UdpDictServer(int port) throws SocketException {
        super(port);
        dict = new HashMap<String,String >();
        dict.put("dog", "小狗");
        dict.put("cat", "小猫");
        dict.put("pig","小猪");
    }

    //start方法可以直接继承下来，直接使用
    //重写process方法
    @Override
    public String process(String request) {

        String response = dict.getOrDefault(request,"您查找的单词不存在！");
        return dict.getOrDefault(request,"您查找的单词不存在！");

    }

    public static void main(String[] args) throws IOException {
        //
        UdpDictServer server = new UdpDictServer(9090);
        server.start();

    }
}
